package com.liu.communitysystemend.module.ParkingRecord.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.liu.communitysystemend.module.ParkingRecord.domain.ParkingRecord;
import com.liu.communitysystemend.module.ParkingRecord.service.ParkingRecordService;

import com.liu.communitysystemend.utils.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author liu
 * @create 2023-03-17 20:44
 */
@RestController
@RequestMapping("/api/parkingRecord")
public class ParkingRecordController {
    @Autowired
    private ParkingRecordService parkingRecordService;

    @ApiOperation("更新来访信息")
    @GetMapping("/get/{id}")
    public Result<ParkingRecord> getComplaints(@PathVariable("id")String id){
        return Result.success(parkingRecordService.getVisitorById(id));
    }

    @ApiOperation("更新来访信息")
    @PostMapping("modify")
    public Result<ParkingRecord> save(@RequestBody ParkingRecord parkingRecord) {
        return Result.success(parkingRecordService.update(parkingRecord));
    }

    @ApiOperation("添加来访信息")
    @PostMapping("add")
    public Result<ParkingRecord> add(@RequestBody ParkingRecord parkingRecord){
        return Result.success(parkingRecordService.add(parkingRecord));
    }

    @ApiOperation("查询来访列表(分页)")
    @PostMapping("page")
    public Result<Page<ParkingRecord>> getPage(@RequestBody ParkingRecord parkingRecord) {
        return Result.success(parkingRecordService.getPage(parkingRecord));
    }

    @GetMapping("delete/{id}")
    @ApiOperation("删除来访")
    public Result deleteById(@PathVariable("id") String id) {
        return parkingRecordService.deleteById(id) > 0 ? Result.success() : Result.failed();
    }

    @ApiOperation("来访test")
    @GetMapping("/test")
    public Result test(){
        return Result.success(parkingRecordService.test());
    }

}